package com.example.supplychainbackend.service.Impl;

import com.example.supplychainbackend.controller.dto.TodoDto;
import com.example.supplychainbackend.controller.dto.trace.CodeDto;
import com.example.supplychainbackend.controller.dto.trace.TimelineDto;
import com.example.supplychainbackend.controller.dto.trace.TraceInfoDto;
import com.example.supplychainbackend.dao.TodoDao;
import com.example.supplychainbackend.dao.design.BOMDao;
import com.example.supplychainbackend.dao.plan.PlanOrderDao;
import com.example.supplychainbackend.dao.production.ProductionProcessDao;
import com.example.supplychainbackend.dao.production.ProductionSchedulingDao;
import com.example.supplychainbackend.dao.production.ProductionWorkorderDao;
import com.example.supplychainbackend.dao.project.ProjectDocsDao;
import com.example.supplychainbackend.dao.project.ProjectPlanDao;
import com.example.supplychainbackend.dao.quality.InspectionOrderDao;
import com.example.supplychainbackend.dao.quality.InspectionRequestDao;
import com.example.supplychainbackend.dao.sales.ContractDao;
import com.example.supplychainbackend.dao.sales.OrderDao;
import com.example.supplychainbackend.dao.warehouse.InboundBillDao;
import com.example.supplychainbackend.dao.warehouse.OutboundBillDao;
import com.example.supplychainbackend.entity.TodoEntity;
import com.example.supplychainbackend.entity.design.BOMEntity;
import com.example.supplychainbackend.entity.plan.MaterialInfoEntity;
import com.example.supplychainbackend.entity.plan.PlanOrderEntity;
import com.example.supplychainbackend.entity.production.ProductionProcessEntity;
import com.example.supplychainbackend.entity.production.ProductionSchedulingEntity;
import com.example.supplychainbackend.entity.production.ProductionWorkorderEntity;
import com.example.supplychainbackend.entity.project.PlanDetailEntity;
import com.example.supplychainbackend.entity.project.ProjectPlanEntity;
import com.example.supplychainbackend.entity.quality.InspectionOrderEntity;
import com.example.supplychainbackend.entity.quality.InspectionRequestEntity;
import com.example.supplychainbackend.entity.sales.ContractEntity;
import com.example.supplychainbackend.entity.sales.OrderEntity;
import com.example.supplychainbackend.entity.warehouse.InboundBillEntity;
import com.example.supplychainbackend.entity.warehouse.OutboundBillEntity;
import com.example.supplychainbackend.mapper.TodoMapper;
import com.example.supplychainbackend.service.TodoService;
import com.example.supplychainbackend.service.TraceService;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
public class TodoServiceImpl implements TodoService {
    private final TodoDao todoDao;
    private final TodoMapper mapper;
    private final String sep = System.lineSeparator();


    @Override
    public List<TodoDto> getAllTodoByEid(String eid) {
        return mapper.toDtoList(todoDao.findAllByEid(eid));
    }

    @Override
    public List<TodoDto> getAllTodo() {
        return mapper.toDtoList(todoDao.findAll());
    }

    @Override
    public TodoDto getTodoById(String id) {
        return mapper.toDto(todoDao.findById(id).get());
    }

    @Override
    public String createTodo(TodoDto dto) {
        return todoDao.save(mapper.toEntity(dto)).getId();
    }

    @Override
    public String updateTodo(TodoDto dto) {
        return todoDao.save(mapper.toEntity(dto)).getId();
    }

    @Override
    public String deleteTodoById(String id) {
        todoDao.deleteById(id);
        return id;
    }

    @Override
    public Boolean handleTodo(String id) {
        TodoEntity entity = todoDao.findById(id).get();
        entity.setCompleted(true);
        entity = todoDao.save(entity);
        return entity.getCompleted();
    }
}
